#ifndef _FIG_PLAYER_CRAFT_H_
#define _FIG_PLAYER_CRAFT_H_

#include "fig_craft.h"
#include "fig_bullet.h"
#include "fig_player_shadow.h"

#include "input/joystick.h"

class FIGBulletManager;
class FIGEnemyManager;
class FIGUIText;

class FIGPlayerCraft : public FIGCraft, public input::JoystickListener 
{
public:
    
	const static float			POSITION_COUNTER_DURATION;
	const static int			WEAPON_MAX_POWER = 2;
	const static float			ARMOR_MAX_COUNTER;
	const static int			GHOST_MODE_MAX_COUNTER = 1;
    
	
    
	    
	enum WEAPON_TYPE
	{
		WEAPON_BULE,
		WEAPON_RED,
		WEAPON_GREEN,
		WEAPON_C
	};
    
	enum STATE
	{
		STATE_NOTSHOWNYET,
		STATE_SPAWN,
		STATE_GHOSTMODE_COMEIN,
		STATE_GHOSTMODE,
		STATE_NORMAL,
		STATE_DYING,
		STATE_LEVEL_COMPLETE_GO_UP,
		STATE_C
	};
    
    
	struct		ShipSpriteInfo
	{
		enum	CRAFT_SPRITES
		{
			CRAFT_LEFT5,
			CRAFT_LEFT4,
			CRAFT_LEFT3,
			CRAFT_LEFT2,
			CRAFT_LEFT1,		
			CRAFT_MIDDLE,
			CRAFT_RIGHT1,
			CRAFT_RIGHT2,
			CRAFT_RIGHT3,
			CRAFT_RIGHT4,
			CRAFT_RIGHT5,
			CRAFT_SPRITE_COUNT
		};

		ShipSpriteInfo();
		~ShipSpriteInfo();

		void								Tick(	float dt, const math::Vec2& Pos, float Rotation);
		void								Reset(const math::Vec2& Pos);

		void								AddSprite(const std::string& Str);
		void								GoingLeft();
		void								GoingRight();
		void								GoingMid();   

		CRAFT_SPRITES						m_ShipIndex;
		float								m_PositionCounter;
		math::Vec2							m_PrevSwayPos;

		std::vector<ui::UISprite*>			m_Sprites;
				
	};
	
	struct		Guardian
	{
		enum LaserState
		{
			STATE_NONE,
			STATE_EXPANDING,
			STATE_SHRINKING,
			STATE_COUNT


		};

		Guardian();
		void DELEGATE_CALL		OnButtonClick(ui::UIWidget::WIDGET_EVENT Event, 
												ui::UIWidget* pWidget);
		void					Tick(	float dt , 
										const math::Vec2& MainShipPos,
										const math::Vec2& MainShipSize
										);
		void					Render(const math::Vec2& Offset,										
										float Scale);

		void					ForceFinish();
		void					IncreaseCoolDown();
		void					Start(bool Force);


		bool					m_bHasGurdian;
		math::Counter			m_CoolDown;
		math::Counter			m_Counter;
		math::Counter			m_CounterArrow;
		math::Vec2				m_Pos;
		
		ui::UIProgress*			m_pUIProgress;
		ui::UIWidget*			m_pUISpecial;
		ui::UIWidget*			m_pUITutorialArrow;  		

		bool					m_IsAppearing;
		bool					m_IsDisappearing;
		bool					m_IsShowingTutorialArrow;

		ui::UISprite			m_MiniPlayer;
		ui::UISprite			m_SpriteLaser;
		ui::UISprite			m_SpriteLaserShootPoint;
		ui::UISprite			m_SpriteLaserHit;


		float					m_SpriteLaserShootRotation;

		float					m_LaserHitPos;
		float					m_LaserSpritePosY;
		LaserState				m_LaserState;
		float					m_LaserWidthScale;
		float					m_Accel;

	};


	struct Armor
	{	
		Armor();
		void					Tick(float dt);
		void					Render(	const math::Vec2& Offset,
										const math::Vec2& ShipPos,
										float Scale);

		void					Activate();
		bool					IsActivating()const;

		float					m_Counter;
		ui::UISprite			m_Sprite;		
		float					m_Rotation;
		math::Counter			m_BlinkCounter;
			
	};

	struct			Tilt
	{
		Tilt();
		void					Tick(float dt,
									 math::Vec2& ShipPos,
									 const math::Vec2& ShipSize
										);
		void					OnJoystickTilt(const math::Vec3& AxisState);
		void					MouseMove(const math::Vec2& From, const math::Vec2& To);

		void					OnMOGAMotion(float X,float Y);

		math::Vec2				m_Dir;
		math::Vec2				m_Origin;
		bool                    m_ToGetOrigin;
		math::Vec2				m_PreviousPosition;	
	};


	struct			NuclearBomb
	{
		

		NuclearBomb();
		void								Tick(
												float dt,
												const math::Vec2& Pos
												);
		void								ShowCount();
		void								Reset();

		void DELEGATE_CALL					OnButtonBomb(
												ui::UIWidget::WIDGET_EVENT Event, 
												ui::UIWidget* pWidget);

		math::Counter						m_CoolDown;
		ui::UIWidget*						m_pUIBombCount;
		ui::UIWidget*						m_pUIBomb;
		ui::UIProgress*						m_pUIProgress;
		FIGSfx*								m_pCurrentSFX;

	};

	
    
	static FIGPlayerCraft&				Instance();
    
	
	virtual math::Vec2					GetRocketDistFromCenter(){ return math::Vec2(0.05f,0); };
	virtual const math::Vec2&			GetSize();

	virtual void						Render(const math::Vec2& Offset,float Scale);
	virtual void						RenderDebug(const math::Vec2& Offset,float Scale);
	virtual void						GotDamage(float Amount,FIGBullet* pBullet, bool Force);
	virtual void						Tick(float dt);
	virtual	void						OnJoystickTilt(const math::Vec3& AxisState);
    
	
	void								OnMOGAMotionEvent(float X,float Y);
    
	void								CacheRender();
	void								OnMouseMove(const math::Vec2& From, const math::Vec2& To);
	void								OnMouseDown(const math::Vec2& Pos);
	void								OnMouseUp(const math::Vec2& Pos);
	void								OnICadeMove(const math::Vec2& Pos);
	void								OnControllerBomb();
	void								OnControllerGuardian();



	void								UpgradeWeapon(WEAPON_TYPE Type);
	void								SwitchWeapon();
	void								RestoreHealth() { m_Life = m_MaxLife; };
	void								SuperArmor() { m_Armor.Activate(); };
	void								PickupRocketShootToAllDir();
	void								PickupStar() { m_PickupStarCount++; };
	void								Pickup1Up();
	void								PickupGuardianAngel() {};
	void								IncreaseBombs();
	bool								CanHit() const;	
	void								OnLevelComplete();
	void								StartNewLevel();
	void								IncreaseSpecialPowerCoolDown();
	void								ResetToDefault();
	void								MarkGyroscope() { m_Tilt.m_ToGetOrigin = true; };
	void								ForceStartGuardian() { m_Guardian.Start(true); };
	void								SetIsShootButtonPressed(bool b) { m_IsShootButtonPressed = b; };

	//bool								m_SkipAd;
	    
protected:
    
	FIGPlayerCraft();
	~FIGPlayerCraft();
    
	virtual void						OnDie();
    
	

	void								RenderShip(	const math::Vec2&	Pos,
													int					ShipIndex,
													const math::Vec2	Offset,
													COLOR				c,													
													float				Scale
													);
    
	
	

	void								Tick_States(float dt);
	void								Tick_BulletShooting(float dt);
	void								Tick_LevelCompleteGoUp(float dt);
	

    
	void								SpawnNewCraft();
	void								ComingIntoTheScreen(float dt);
    
	
	void								ShowShipCount();
    
    
	FIGBullet::SHOOT_STYLES				GetShootStyle();
    
	ui::UISprite						m_BoasterSprite;
	 
	ui::UIProgress*						m_pUIProgress_Health;  
	ui::UIWidget*						m_pUIShipCount;
	

	ShipSpriteInfo						m_ShipSpriteInfo;

	// Structs ---------
	Guardian							m_Guardian;
	Armor								m_Armor;
	Tilt								m_Tilt;
	NuclearBomb							m_NuclearBomb;
	//------------------
    
	std::vector<float>					m_Rotations;
	std::vector<float>					m_XAdjustments;

	
	bool								m_bIsMouseDown;
	STATE								m_State;
    
	float								m_GhostModeCounter;
	math::Counter						m_GhostModeBlinkCounter;
    	
	int									m_PickupStarCount;
	float								m_LevelCompeleteCounter;
	FIGPlayerShadow*					m_pLvlCompleteShadowObj;     
	
    
	float								m_DyingCounter;
	float								m_AppearCounter;

	bool								m_IsShootButtonPressed;
	bool								m_bSkipAd;
	math::Vec2							m_SizePlayer;
	bool								m_IsOnICadeMove;
	
};

#endif